/*
 * Created on 2004/9/14
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package libnetdb.dm.assoc.util;

import java.util.NoSuchElementException;

/**
 * @author Cheng-Ru Lin
 *
 *
 */
public class IntegerStack {
	private int[] data = new int[32];
	private int size = 0;
	
	public void pushBack( int x ) {
		if ( size == data.length ) {
			int tmp[] = new int[ size + size];
			System.arraycopy( data, 0, tmp, 0, data.length );
			data = tmp;
		}
		data[size++] = x;
	}
	
	public int popBack() {
		if ( size == 0 ) throw new NoSuchElementException();
		return data[--size];
	}
	
	public int getBack() {
		if ( size == 0 ) throw new NoSuchElementException();
		return data[size-1];
	}
	
	public int getSize() {
		return size;
	}
	
	public int [] toArray() {
		int temp[] = new int[size];
		System.arraycopy( data, 0, temp, 0, size );
		return temp;
	}

}
